package com.example.bigupload.controller;

import com.example.bigupload.domain.AjaxResult;
import com.example.bigupload.domain.FileChunk;
import com.example.bigupload.service.UploadService;
import io.minio.errors.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private UploadService uploadService;



    /**
     * 进行分片校验
     * @param fileChunk
     * @return
     */
    @GetMapping("/upload")
    public AjaxResult checkUpload(FileChunk fileChunk){
        return uploadService.checkUpload(fileChunk);
    }

    /**
     * 进行分片上传
     * @param fileChunk
     * @return
     * @throws IOException
     */
    @PostMapping("/upload")
    public AjaxResult uploadChunkFile(FileChunk fileChunk) throws IOException, ServerException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        return uploadService.uploadChunkFile(fileChunk);
    }



}
